package be.dch.csv.validator;

import be.dch.exceptions.ValidationException;

public class RegExValidator implements CellValidator {

    private transient CellValidator validator;
    private final transient String regex;

    public RegExValidator(final String regex) {
	this.regex = regex;
    }

    public RegExValidator(final CellValidator validator, final String regex) {
	this.validator = validator;
	this.regex = regex;
    }

    public void validate(final String input) throws ValidationException {
	if (this.validator != null) {
	    this.validator.validate(input);
	}
	if (!input.matches(this.regex)) {
	    throw new ValidationException(input + "does not matches regulator exception [" + this.regex + "].");
	}

    }

}
